<?php 

include '../function.php'; 
// 链接数据库 
$link = @new mysqli("127.0.0.1", "root", "", "school");  
// 判断是否链接成功 
if ($link->connect_errno) {  	
	echo $link->connect_error;  
} 

// 设置编码 
$link->query("set names utf8");  

$sql = "insert into stu (name,sex) values(?,?)"; 


$stmt = $link->prepare($sql); 


if (!$stmt) {  	

	exit("<b>发生错误:</b>%s".$link->error);

	} else { 	

	$stmt->bind_param("ss", $name, $sex); 

	//绑定参数 	
	$arr = array("name" => "王五", "sex" =>'18'); 

	extract($arr); 	

	if ($stmt->execute()) { 	

		printf("影响的条数%s<br/>", $stmt->affected_rows); 	
		printf("最后揑入的%s<br/>", $stmt->insert_id); 	} else { 		
		printf("错误代码:%s,<br/>错误内容:%s", $stmt->errno,$stmt->error); 	
	} 

	$stmt->close(); 	
	$link->close(); 	
}

















 ?>